<?php

namespace App\Http\Controllers\CallingCards\RMS;

use App\Http\Controllers\BaseController;
use App\Http\Validate\CallingCards\InvestmentEmployee\InvestmentEmployeeValidate;
use App\Models\FeishuCallingCard\FeishuCallingCardInvestmentEmployeeModel;
use App\Service\CallingCards\Rms\InvestmentEmployeeService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class InvestmentEmployeeController extends BaseController
{
    /**
     * 列表
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function index(Request $request): JsonResponse
    {
        $params = InvestmentEmployeeValidate::listValidate($request->all());
        return self::success(InvestmentEmployeeService::list($params));
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function insert(Request $request): JsonResponse
    {
        $params = InvestmentEmployeeValidate::insertValidate($request->all());
        InvestmentEmployeeService::insert($params);
        return self::success();
    }

    /**
     * 编辑
     *
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function update(Request $request, int $id): JsonResponse
    {
        $params = InvestmentEmployeeValidate::updateValidate($request->merge(["id" => $id])->all());
        InvestmentEmployeeService::update($params);
        return self::success();
    }

    /**
     * 删除
     *
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function del(Request $request, int $id): JsonResponse
    {
        $params = InvestmentEmployeeValidate::delValidate($request->merge(["id" => $id])->all());
        InvestmentEmployeeService::del($params);
        return self::success();
    }

    public function saveAll(Request $request)
    {
        InvestmentEmployeeService::addFormAll($request->all());
        return $this->success();
    }


}
